﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WpfApp_SmartParking_Entities;
using WpfApp_SmartParking_IService;

namespace WpfApp_SmartParking_Service;

public class UserService : BaseService,IUserService
{
    public UserService(DbContext dbContext):base(dbContext)
    {
            
    }

    public IEnumerable<SysUser> GetUsers(string key)
    {
        // 需要将搜索关键词加入判断。。。。。。
        return this.Query<SysUser>(m =>

            string.IsNullOrEmpty(key) ||

            m.Name.Contains(key) ||

            m.Address.Contains(key) ||

            m.Phone.Contains(key)
        );
    }

    /// <summary>
    /// 登录
    /// </summary>
    /// <param name="username"></param>
    /// <param name="password"></param>
    /// <returns></returns>
    /// <exception cref="NotImplementedException"></exception>
    public SysUser? Login(string username, string password)
    {
        List<SysUser> _users = this.Query<SysUser>(it => it.Name == username && it.Password == password).ToList();
        return _users.FirstOrDefault();
    }
}
